package com.ruoyi.account.service.impl;

import com.ruoyi.account.domain.HouseAccountT;
import com.ruoyi.account.mapper.HouseAccountTMapper;
import com.ruoyi.account.service.IHouseAccountTService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 对账Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-09-07
 */
@Service
public class HouseAccountTServiceImpl implements IHouseAccountTService 
{
    @Autowired
    private HouseAccountTMapper houseAccountTMapper;

    /**
     * 查询对账
     * 
     * @param id 对账主键
     * @return 对账
     */
    @Override
    public HouseAccountT selectHouseAccountTById(Long id)
    {
        return houseAccountTMapper.selectHouseAccountTById(id);
    }

    /**
     * 查询对账列表
     * 
     * @param houseAccountT 对账
     * @return 对账
     */
    @Override
    public List<HouseAccountT> selectHouseAccountTList(HouseAccountT houseAccountT)
    {
        return houseAccountTMapper.selectHouseAccountTList(houseAccountT);
    }

    /**
     * 新增对账
     * 
     * @param houseAccountT 对账
     * @return 结果
     */
/*    @Override
    public int insertHouseAccountT(HouseAccountT houseAccountT)
    {
        return houseAccountTMapper.insertHouseAccountT(houseAccountT);
    }*/

    /**
     * 修改对账
     * 
     * @param houseAccountT 对账
     * @return 结果
     */
    @Override
    public int updateHouseAccountT(HouseAccountT houseAccountT)
    {
        return houseAccountTMapper.updateHouseAccountT(houseAccountT);
    }

    @Transactional
    @Override
    public void checkAccount(List<HouseAccountT> list, String datetime1, String costWay) {
        for (HouseAccountT accountVO : list) {
            HouseAccountT costDetailVO = new HouseAccountT();
            accountVO.setCostWay(costWay);
            costDetailVO = houseAccountTMapper.getCostForAccount(accountVO);
            if (costDetailVO == null) {
                accountVO.setCostmoney(String.valueOf(accountVO.getCostMoney()));
                accountVO.setCheckSts("1");
                houseAccountTMapper.insertCostInfoByHouseId(accountVO);
                houseAccountTMapper.updateDoorByHouseId(accountVO);
                houseAccountTMapper.updateOrderInfo(accountVO);
            } else {
                houseAccountTMapper.updateCostCheckSts(accountVO);
            }
            HouseAccountT checkVO = new HouseAccountT();
            checkVO.setAccountDate1(datetime1);
            checkVO.setCostWay(costWay);
            HouseAccountT checkTempVO = new HouseAccountT();
            checkTempVO = houseAccountTMapper.getAccountForDate(checkVO);
            if(checkTempVO == null){
                 houseAccountTMapper.insertHouseAccountT(checkVO);
            }
        }

    }

    /**
     * 批量删除对账
     * 
     * @param ids 需要删除的对账主键
     * @return 结果
     */
    @Override
    public int deleteHouseAccountTByIds(Long[] ids)
    {
        return houseAccountTMapper.deleteHouseAccountTByIds(ids);
    }

    /**
     * 删除对账信息
     * 
     * @param id 对账主键
     * @return 结果
     */
    @Override
    public int deleteHouseAccountTById(Long id)
    {
        return houseAccountTMapper.deleteHouseAccountTById(id);
    }
}
